<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head>
    <base href="<%=basePath%>" />
    <script type="text/javascript">
		var path = "<%=basePath%>";
	</script>
    <title>Radiator Storage Management</title>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>beshs/css/content.css" />
	<script type="text/javascript" src="<%=basePath%>resources/jquery/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="<%=basePath%>resources/datepicker/datepicker.js"></script>
	<!-- 页面特效 -->
	<jsp:include page="/beshs/res-refer/page-effect-reference.jsp" />
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
	<!-- 表单校验 -->
	<jsp:include page="/resources/resource-refer/component-validform-reference.jsp" />
		<style type="text/css">
.a-upload {
	padding: 4px 10px;
	height: 20px;
	line-height: 20px;
	position: relative;
	cursor: pointer;
	color: #888;
	background: #fafafa;
	border: 1px solid #ddd;
	border-radius: 4px;
	overflow: hidden;
	display: inline-block;
	*display: inline;
	*zoom: 1
}

.a-upload  input {
	position: absolute;
	font-size: 100px;
	right: 0;
	top: 0;
	opacity: 0;
	filter: alpha(opacity = 0);
	cursor: pointer
}

.a-upload:hover {
	color: #444;
	background: #eee;
	border-color: #ccc;
	text-decoration: none
}
</style>
  </head>
  <script type="text/javascript">
  	$(function(){
		$("form[name='sinkerDictForm']").Validform({
			btnSubmit: "input[name='submit']",
			btnReset: "input[name='reset']",
			tiptype: function(msg, o, cssctl){
				//msg：提示信息;
				//o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
				//cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
				if(!o.obj.is("form")){//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
					var objtip=o.obj.siblings(".Validform_checktip");
					cssctl(objtip,o.type);
					objtip.text(msg);
				} else {
					var objtip=o.obj.find("#msgdemo");
					cssctl(objtip,o.type);
					objtip.text(msg);
				}
			},
			postonce: true, //开启二次提交防御，在数据成功提交后，表单将不能再继续提交
			showAllError: true, //提交表单时所有错误提示信息都会显示
			ajaxPost:true,
			beforeSubmit: function(curform) { //在验证成功后，表单提交前执行的函数，curform参数是当前表单对象
// 				curform.submit();
				return true; //这里明确return false的话表单将不会提交
			}
		});
  	});
  
  	/**
  	 * 散热器信息提交回调
  	 * @param {Object} data
  	 */
  	function uploadCallBack(data) {
  		var resJson = $.parseJSON(data);
  		if(resJson.success) {
  			Dialog.alert("Successful Operation！", function() {
  				var index = parent.layer.getFrameIndex(window.name)
				parent.window.frames["c_content_content"].location = path+"beshs/sinkerStandardDictAction!queryStandardSinkerPage.do?date="+new Date();
  				parent.layer.close(index);
  			});
  		} else {
  			Dialog.alert("System error, please contact adminitrator！");
  		}
  	}
  </script>
  <body>
    <div class="content_all">
  		<!--导航条-->
  		<div class="insertinfo_table">
      		<form action="<%=basePath%>beshs/sinkerStandardDictActionJson!saveOrUpdateSinkerDict.do" name="sinkerDictForm"
      			enctype="multipart/form-data" method="post" target="async_frame_submit">
      		  <input name="sinkerDict.id" type="hidden" class="s_input" value="<s:property value='sinkerDict.id' />" />
      		  <input name="sinkerDict.dictSerious" type="hidden" class="s_input" value="<s:property value='sinkerDict.dictSerious' />" />
      		  <input name="sinkerDict.creator" type="hidden" class="s_input" value="<s:property value='sinkerDict.creator' />" />
      		  <iframe name="async_frame_submit" id="async_frame_submit" style="display: none;"></iframe>
      		  <table width="100%" border="0" cellspacing="0" cellpadding="0">
        		<tr>
        			<th>Radiator Model：</th>
          			<td><input name="sinkerDict.sinkType" type="text" class="s_input" value="<s:property value='sinkerDict.sinkType' />" 
          					datatype="/^[\-0-9a-zA-Z\u4e00-\u9fa5]{2,25}$/" sucmsg="Radiator Model Verification Passed！" nullmsg="Please enter radiator model！" errormsg="Radiator Model only can be composed of letters,numbers and dashes within 2~25 characters！" />
            			&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip">Radiator Model only can be composed of letters,numbers and dashes within 2~25 characters！</div></td>
          			<th>Radiator Brand：</th>
          			<td><input name="sinkerDict.brand" type="text" class="s_input" value="<s:property value='sinkerDict.brand' />" 
          					datatype="/^[\-0-9a-zA-Z\u4e00-\u9fa5]{2,25}$/" ignore="ignore" errormsg="Radiator Brand only can be composed of letters,numbers and dashes within 2~25 characters！" />
          				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<th>Radiator Width：</th>
          			<td><input name="sinkerDict.sinkWidth" type="text" class="s_input" value="<s:property value='sinkerDict.sinkWidth' />" 
          					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" ignore="ignore" errormsg="Please enter integral or float type value！" />mm
          				<div class="Validform_checktip"></div></td>
            		<th>Radiator Length：</th>
          			<td><input name="sinkerDict.sinkLength" type="text" class="s_input" value="<s:property value='sinkerDict.sinkLength' />" 
          					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" ignore="ignore" errormsg="Please enter integral or float type value！" />mm
          				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
            		<th>Radiator Height：</th>
          			<td><input name="sinkerDict.sinkHeight" type="text" class="s_input" value="<s:property value='sinkerDict.sinkHeight' />" 
          					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" ignore="ignore" errormsg="Please enter integral or float type value！" />mm
            			<div class="Validform_checktip"></div></td>
        		    <th>Radiator Central Distance：</th>
          			<td><input name="sinkerDict.sinkCenDis" type="text" class="s_input" value="<s:property value='sinkerDict.sinkCenDis' />" 
          					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" sucmsg="Radiator Central Distance Verification Passed！" nullmsg="Please enter radiator central distance！" errormsg="Please enter integral or float type value！" />
            			mm&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip">Please enter integral or float type value！</div></td>
        		</tr>
        		<tr>
        		    <th>Power Calculation of Single Fin：</th>
          			<td><input name="sinkerDict.calPower" type="text" class="s_input" value="<s:property value='sinkerDict.calPower' />" 
          					datatype="n1-10|/^([1-9]\d*\.\d*|0\.\d*[1-9]\d*|0?\.0+|0)$/" sucmsg="Power Calculation of Single Fin Verification Passed！" nullmsg="Please enter power calculation of single fin！" errormsg="Please enter integral or float type value！" />
            			W&nbsp;<span style="color:#FF0000;">*</span>
            			<div class="Validform_checktip">Please enter integral or float type value！</div></td>
            		<th>Model Picture：</th>
          			<td>
          				<script type="text/javascript">
	        				$(function(){
	            				<s:if test="attachFileMap == null">
	            					addListenerToFileField();
	            				</s:if>
	    					});
	        				
	        				/**
	            			 * 为文件域追加状态切换事件处理函数
	            			 * @return {TypeName} 
	            			 */
	            			function addListenerToFileField() {
	            				$("input[name='attachFile']").change(function(){
             						var absPath = $("input[name='attachFile']").val();
             						if(absPath!=null && $.trim(absPath)!="") {
             							var fileIndex = absPath.lastIndexOf("\\")>0?absPath.lastIndexOf("\\"):absPath.lastIndexOf("/");
             							//读取上传的文件名
             							var fileName = "";
             							if(fileIndex<0) {
             								fileName = absPath;
             							} else {
             								fileName = absPath.substring(fileIndex+1, absPath.length);
             							}
             							//读取上传附件的文件类型
             							var dotIndex = fileName.lastIndexOf(".");
             							var fileType = fileName.substring(dotIndex+1, fileName.length);
             							var verifyTagIndex = "jpg,JPG,gif,GIF,bmp,BMP,png,PNG,jpeg,JPEG,ico,ICO".indexOf(fileType);
             							if(verifyTagIndex < 0) {
             								Dialog.alert("Prompt: only support jpg,JPG,gif,GIF,bmp,BMP,png,PNG,jpeg,JPEG,ico,ICO format file!");
             								//清空文件域
                     						var attachFile = $("input[name='attachFile']");
                     						attachFile.after(attachFile.clone().val(""));
                     						attachFile.remove();
                     						//文件域事件监听
                     						addListenerToFileField();
             								return;
             							}
             							$("input[name='attachFile']").hide("fast");
             							//加载文件名
             							var fileNameLoad = "<p class='fileName_load_txt'>" + 
             													fileName + "&nbsp;&nbsp;" +
             													"<a class='fileName_load_txt' style='text-decoration: underline' target='_self' href='javascript:void(0)'>Delete</a>" +
             												"</p>";
             							$("input[name='attachFile']").parent("td").append(fileNameLoad);
             							//文件名删除处理
             							$("a.fileName_load_txt").click(function(){
             								removeFileNameTxt();
             							});
             						}
             					});
	            			 }
	            			 
	            			 /**
         					 * 删除上传文件加载名称
         					 */
         					function removeFileNameTxt() {
         						$("p.fileName_load_txt").remove();
         						//清空文件域
         						var attachFile = $("input[name='attachFile']");
         						attachFile.after(attachFile.clone().val(""));
         						attachFile.remove();
         						$("input[name='attachFile']").show("fast");
         						//文件域事件监听
         						addListenerToFileField();
         					}
	            			
	            			/**
	            			 * 删除已上传的散热器附件
	            			 */
	            			function deleteAttachFile(sinkerDictUID) {
	            				//异步删除系统附件
	            				Dialog.confirm("Are you sure to delete this attachment?", function() {
	            					$.getJSON(path+"beshs/sinkerStandardDictActionJson!deleteSinkerDictAttach.do?date="+new Date(), {
	            						sinkerDictUID: sinkerDictUID
	            					}, function(data) {
	            						if(data.success) {
	            							Dialog.alert("Successful Operation！", function() {
	            								//处理页面效果
	            	            				$("p.fileName_load_txt").parent("td").empty().append("<input name='attachFile' type='file' class='s_input' />");
	            	            				addListenerToFileField();
	            							});
	            						} else {
	            							Dialog.alert("System error, please contact adminitrator！");
	            						}
	            					});
	            				});
	            			}
	            			
	            			function downloadAttach(fileMappingUID) {
	            				window.location = path + "beshs/fileMappingAction!downloadAttachFile.do?fileMappingUID="+fileMappingUID+"&date="+new Date();
	            			}
        				</script>
        				<s:if test="attachFileMap != null">
            				<p class='fileName_load_txt'>
            					<a href="javascript:downloadAttach('<s:property value='attachFileMap.id' />')"><s:property value="attachFileMap.orFilename" />.<s:property value="attachFileMap.fileType" /></a>
            					<a class='fileName_load_txt' style='text-decoration: underline' target='_self' href="javascript:deleteAttachFile('<s:property value='sinkerDict.id' />')">[Delete]</a>
            				</p>
            			</s:if>
            			<s:else>
            			  				 <a href="javascript:;" class="a-upload"> <input type="file" name="attachFile" id="">Upload File</a> 
            			</s:else>
          			</td>
        		</tr>
        		<tr>
        			<th>Remark：</th>
          			<td colspan="3">
          				<textarea name="sinkerDict.remrak" cols="45" rows="3"
          					datatype="*1-400" ignore="ignore" errormsg="请填写有效内容，控制在1-400个字符！" >
          					<s:property value='sinkerDict.remrak' /></textarea>
          				<div class="Validform_checktip"></div></td>
        		</tr>
        		<tr>
          			<td style="border:none;" colspan="4" align="center">
          				<input name="submit" type="submit" value="Submit" class="s_btn" />
            			<input name="reset" type="reset" value="Reset" class="s_btn"/></td>
        		</tr>
      		</table></form>
  		</div>
	</div>
	<div class="clear"></div>
  </body>
</html>
